// 导入createRouter方法和创建History路由模式的createWebHistory方法
import { createRouter, createWebHistory } from 'vue-router'

// 具体各个路由项，待补充
const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('@/views/home/index.vue'),
    meta: {
      title: '学生信息',
    },
  },
  {
    path: '/todo',
    name: 'Todo',
    component: () => import('@/views/todo/index.vue'),
    meta: {
      title: '待办事项',
    },
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('@/views/settings/index.vue'),
    meta: {
      title: '用户设置',
    },
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || 'Vue Demo'

  // 这里可以添加路由守卫逻辑，比如检查用户是否登录
  next()
})

export default router
